package com.esyoga.yoyoga.handler;

import com.esyoga.yoyoga.pojo.TStudent;
import com.esyoga.yoyoga.pojo.TTrainer;
import lombok.Data;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/user1")
@Data
public class User1Handler {

    @RequestMapping("/getUserInfo")
    @ResponseBody
    public Map<String,Integer> getUserInfo(HttpServletRequest request){
        HttpSession session = request.getSession();
        Integer userType = (int) session.getAttribute("userType");
        Integer userId = 0;
        if (userType==0){
            TStudent student = (TStudent) session.getAttribute("tstudent");
            userId = student.getsId();
        }else if (userType==1){
            TTrainer trainer = (TTrainer) session.getAttribute("tTrainer");
            userId = trainer.gettId();
        }
        Map<String,Integer> userInfos = new HashMap<>();
        userInfos.put("userType",userType);
        userInfos.put("userId",userId);
        return userInfos;
    }
}
